package za.ac.cput.arrowgame.service.requesthandler;

import java.util.ArrayList;
import java.util.List;
import za.ac.cput.arrowgame.app.factories.AppFactory;

public class Request {

    private String request;
    private List<Command> commands;

    public Request() {
        commands = new ArrayList<Command>();
    }

    public void setRequest(String request) {
        this.request = request;
    }

    public List<Command> getCommands() {
        return commands;
    }

    public void createCommand() {
        if (request != null) {
            String[] split = request.split("(?<=\\d)(?=\\p{L})");
            for (String string : split) {
                String[] split1 = string.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
                Command command = AppFactory.getInstance().createCommand();
                for (String string1 : split1) {
                    if (string1.matches("[a-zA-Z]")) {
                        command.setMove(string1);
                    }
                    if (string1.matches("[0-9]+")) {
                        command.setAmount(Integer.valueOf(string1));
                    }
                }
                this.commands.add(command);
            }
        }
//            for (int i = 0; i < split.length; i++) {
//                Command command = AppFactory.getInstance().createCommand();
//
//                this.commands.add(command);
//            }
//            for (int i = 0; i < split.length; i++) {
//                Command command = AppFactory.getInstance().createCommand();
//                if (split[i].matches("[a-zA-Z]")) {
//                    command.setMove(split[i]);
//                }
//                if (split[i].matches("[0-9]+")) {
//                    command.setAmount(Integer.valueOf(split[i]));
//                }
//                this.commands.add(command);
//            }
//            for (String string : split) {
//                Command command = AppFactory.getInstance().createCommand();
//                if (string.matches("[a-zA-Z]")) {
//                    command.setMove(string);
//                }
//                if (string.matches("[0-9]+")) {
//                    command.setAmount(Integer.valueOf(string));
//                }
//                this.commands.add(command);
//            }
//        } else {
//            throw new InvalidInput("No request fould");
//        }
//    }
    }
}
